package com.example.hotel;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class Office_tool extends Activity implements OnClickListener {
	final Context context = this;
	Dialog show_message;
	TextView message;
	Integer a = 0;
	Integer b = 1;
	Integer c = 2;
	Integer tx1 = 0;
	Integer tx2 = 1;
	Integer tx3 = 2;
	int indext = 3;
	int i = 0;
	int i0 = 0;
	int i1 = 1;
	int i2 = 2;
	int j1 = 1;
	int j2 = 2;
	int j3 = 3;
	Integer item = 0;
	Integer item1 = 0;
	String[] menu = { "OfficeSuite Pro", "Quickoffice Pro", "Kingsoft Office",
			"Adobe Reader", "Google Translate", "Dictionary" };
	String[] it = { "com.mobisystems.editor.office_registered",
			"com.qo.android.tablet.am", "", "com.adobe.reader",
			"com.google.android.apps.translate", "com.socialnmobile.colordict" };
	String wellcome1 = "";
	Button bt_left, bt_right;
	TextView tv_txt1, tv_txt2, tv_txt3, tv_menu, wellcome;
	ImageView imv_img1, imv_img2, imv_img3, image_cart, backhome, image_msg,
			image_bill;
	Integer[] Image = { R.drawable.office08, R.drawable.office02,
			R.drawable.office06, R.drawable.adodbreader, R.drawable.translate,
			R.drawable.dictionary };
	String lang = "";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hotel_info);
		String strmenu;
		lang = ((Global) getApplicationContext()).lang;
		wellcome = (TextView) findViewById(R.id.tvWellcome);
		bt_left = (Button) findViewById(R.id.left);
		bt_right = (Button) findViewById(R.id.right);
		imv_img1 = (ImageView) findViewById(R.id.image1);
		imv_img2 = (ImageView) findViewById(R.id.image2);
		imv_img3 = (ImageView) findViewById(R.id.image3);
		backhome = (ImageView) findViewById(R.id.imagehome);
		image_cart = (ImageView) findViewById(R.id.image_cart);
		image_msg = (ImageView) findViewById(R.id.image_msg);
		image_bill = (ImageView) findViewById(R.id.image_bill);
		tv_txt1 = (TextView) findViewById(R.id.tv1);
		tv_txt2 = (TextView) findViewById(R.id.tv2);
		tv_txt3 = (TextView) findViewById(R.id.tv3);
		tv_menu = (TextView) findViewById(R.id.tvMenu);
		bt_left.setOnClickListener(this);
		bt_right.setOnClickListener(this);
		imv_img1.setOnClickListener(this);
		imv_img2.setOnClickListener(this);
		imv_img3.setOnClickListener(this);
		backhome.setOnClickListener(this);
		image_cart.setOnClickListener(this);
		image_msg.setOnClickListener(this);
		image_bill.setOnClickListener(this);
		item = Image.length % 3;
		item1 = Image.length - item;
		imv_img1.setImageResource(Image[a]);
		imv_img2.setImageResource(Image[b]);
		imv_img3.setImageResource(Image[c]);
		tv_txt1.setText(menu[i0]);
		tv_txt2.setText(menu[i1]);
		tv_txt3.setText(menu[i2]);
		wellcome.setText(((Global) getApplicationContext()).wellcome);
		TextView tvAmount = (TextView) findViewById(R.id.tvAmount);
		tvAmount.setText("("
				+ ((Global) getApplicationContext()).cart_count.toString()
				+ ")");
		if (lang.equals("th")) {
			strmenu = "โปรแกรมออฟฟิต";
		} else {
			strmenu = "Office Tool";
		}
		tv_menu.setText(strmenu);

		/*------setfonts------*/
		Typeface Font = Typeface.createFromAsset(getAssets(),
				"fonts/PSL-Kittithada.ttf");
		Typeface FontBold = Typeface.createFromAsset(getAssets(),
				"fonts/PSL-KittithadaBold.ttf");
		TextView tv_amount = (TextView) findViewById(R.id.tvAmount);
		tv_txt1.setTypeface(Font);
		tv_txt2.setTypeface(Font);
		tv_txt3.setTypeface(Font);
		tv_amount.setTypeface(Font);
		wellcome.setTypeface(FontBold);
		tv_menu.setTypeface(FontBold);
		/*--------------------*/

	}

	public void onClick(View v) {
		PackageManager manager = getPackageManager();
		Intent is = new Intent(Intent.ACTION_MAIN);
		String it_name;
		switch (v.getId()) {
		case R.id.right:

			if (item == 1 && i + 3 == item1) {

				i += 3;
				i0 += 3;
				i1 += 3;
				i2 += 3;
				j1 += 3;
				j2 += 3;
				j3 += 3;
				imv_img1.setImageResource(Image[i]);
				imv_img2.setImageResource(0);
				imv_img2.setEnabled(false);
				imv_img3.setImageResource(0);
				imv_img3.setEnabled(false);
				tv_txt1.setText(menu[i0]);
				tv_txt2.setText("");
				tv_txt3.setText("");

			} else if (item == 2 && i + 3 == item1) {

				i += 3;
				i0 += 3;
				i1 += 3;
				i2 += 3;
				j1 += 3;
				j2 += 3;
				j3 += 3;
				imv_img1.setImageResource(Image[i]);
				imv_img2.setImageResource(Image[i + 1]);
				imv_img3.setImageResource(0);
				imv_img3.setEnabled(false);
				tv_txt1.setText(menu[i0]);
				tv_txt2.setText(menu[i1]);
				tv_txt3.setText("");

			} else if (i2 + 3 < Image.length) {

				i += 3;
				i0 += 3;
				i1 += 3;
				i2 += 3;
				j1 += 3;
				j2 += 3;
				j3 += 3;
				indext++;
				a = Image[i0];
				b = Image[i1];
				c = Image[i2];
				imv_img1.setImageResource(a);
				imv_img2.setImageResource(b);
				imv_img3.setImageResource(c);
				imv_img1.setEnabled(true);
				imv_img2.setEnabled(true);
				imv_img3.setEnabled(true);
				tv_txt1.setText(menu[i0]);
				tv_txt2.setText(menu[i1]);
				tv_txt3.setText(menu[i2]);
			}

			break;
		case R.id.left:

			if (i > 0 && i0 < Image.length) {
				i -= 3;
				i0 -= 3;
				i1 -= 3;
				i2 -= 3;
				j1 -= 3;
				j2 -= 3;
				j3 -= 3;
				c = Image[i2];
				b = Image[i1];
				a = Image[i0];
				imv_img1.setImageResource(a);
				imv_img2.setImageResource(b);
				imv_img3.setImageResource(c);
				imv_img1.setEnabled(true);
				imv_img2.setEnabled(true);
				imv_img3.setEnabled(true);
				tv_txt1.setText(menu[i0]);
				tv_txt2.setText(menu[i1]);
				tv_txt3.setText(menu[i2]);
			}
			break;
		case R.id.image1:
			try {
				it_name = it[i0];
				is = manager.getLaunchIntentForPackage(it_name);
				startActivity(is);
			} catch (Exception e) {
				Toast.makeText(context, "Not Found " + menu[i0],
						Toast.LENGTH_LONG).show();
			}
			break;
		case R.id.image2:
			try {
				it_name = it[i1];
				is = manager.getLaunchIntentForPackage(it_name);
				startActivity(is);
			} catch (Exception e) {
				Toast.makeText(context, "Not Found " + menu[i1],
						Toast.LENGTH_LONG).show();
			}
			break;
		case R.id.image3:
			try {
				it_name = it[i2];
				is = manager.getLaunchIntentForPackage(it_name);
				startActivity(is);
			} catch (Exception e) {
				Toast.makeText(context, "Not Found " + menu[i2],
						Toast.LENGTH_LONG).show();
			}
			break;
		case R.id.imagehome:
			startActivity(new Intent(Office_tool.this, home.class));
			break;
		case R.id.image_cart:
			((Global) getApplicationContext()).nameCart = "show_cart";
			((Global) getApplicationContext()).callpage = "Office_tool";
			startActivity(new Intent(Office_tool.this, Add_cart.class));
			break;
		case R.id.image_msg:
			((Global) getApplicationContext()).callpage = "Office_tool";
			startActivity(new Intent(Office_tool.this, Message_list.class));
			break;
		case R.id.image_bill:
			((Global) getApplicationContext()).callpage = "Office_tool";
			startActivity(new Intent(Office_tool.this, Billing_history.class));
			break;
		}

	}

}
